/*! 
 * jquery.event.hashchange - v 1.0.0 - http://jquery-ux.com/
 * Copyright (c) 2010 Michael Helgeson, Three Dub Media
 * Open Source MIT License - http://jquery-ux.com/license 
 */
// Created: 2009-12-21 
// Updated: 2010-01-08
// REQUIRES: jquery 1.3+

;(function($){ // secure $ jQuery alias

// add the jquery instance method
$.fn.hashchange = function( fn ){
	return this[ fn ? "bind" : "trigger" ]( "hashchange", fn );
	};
	
// configure the special event
var hashchange = $.event.special.hashchange = {
	
	// optional setting for non-native timer delay
	delay: 200,
	
	// configure the interactions
	setup: function( opts ){ 
	
		opts = opts || {};
		
		// do nothing if native support
		if ( hashchange.support( this ) ) 
			return false;
		// initialize the hash
		var elem = this,
		data = $.data( this, "hashchange", { 
			prev: String( this.location ),
			delay: ( opts || {} ).delay || hashchange.delay
			});
		// set the timeout...
		data.timer = setTimeout(function(){
			var str = String( elem.location );
			// look for any change
			if ( str != data.prev ){
				// remember the new location
				data.prev = str;
				// handle the artificial event
				$.event.handle.call( elem, new $.Event("hashchange"), "used a timer" );
				}
			// recurse
			data.timer = setTimeout( arguments.callee, data.delay );
			}, data.delay );
		},
	
	// destroy the configure interaction
	teardown: function(){
		// do nothing if native support
		if ( hashchange.support( this ) ) 
			return false;
		// stop the timeout
		var data = $.data( this, "hashchange" );
		clearTimeout( data.timer );
		// clean-up	
		$.removeData( this, "hashchange" );	
		},
	
	// determine native browser support
	support: function( elem ){
		if ( hashchange.supported === undefined ){
			hashchange.supported = !!( "onhashchange" in elem ) || 
				$.isFunction( $( elem ).attr("onhashchange","")[0].onhashchange );
			} 
		return hashchange.supported;	
		}
	};

})( jQuery ); // confine scope